home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / ptv1n1.arc / L2.C < prev    next >
Text File  |  1990-06-08  |  818b  |  38 lines

  1. /*
  2.  * *** Listing 2 ***
  3.  *
  4.  * Program to calculate the 16-bit checksum of the stream of bytes
  5.  * from the specified file.  Obtains the bytes one at a time in
  6.  * assembler, via direct calls to DOS.
  7.  */
  8. #include <stdio.h>
  9. #include <fcntl.h>
  10.  
  11. main(int argc, char *argv[]) {
  12.    int Handle;
  13.    unsigned char Byte;
  14.    unsigned int Checksum;
  15.    int ReadLength;
  16.  
  17.    if ( argc != 2 ) {
  18.       printf("usage: checksum filename\n");
  19.       exit(1);
  20.    }
  21.  
  22.    if ( (Handle = open(argv[1], O_RDONLY | O_BINARY)) == -1 ) {
  23.       printf("Can't open file: %s\n", argv[1]);
  24.       exit(1);
  25.    }
  26.  
  27.    if ( !ChecksumFile(Handle, &Checksum) ) {
  28.       printf("Error reading file %s\n", argv[1]);
  29.       exit(1);
  30.    }
  31.  
  32.    /* Report the result */
  33.    printf("The checksum is: %u\n", Checksum);
  34.  
  35.    exit(0);
  36. }
  37.  
  38.